package com.talkweb.securitycamera.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author : frank
 * @date : 2021/2/1 11:24
 */
public class TimeUtils {

    public static final String FORMAT_PATTERN = "yyyy-MM-dd";

    public static String getTimeYYYYMMddHHmmss(long timeStamp) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH：mm：ss");
        String dateString = simpleDateFormat.format(new Date(timeStamp));
        return dateString;
    }

    /** @noinspection deprecation*/
    public static Long getLongTime(String time) {
        Date date = new Date(time);
        return date.getTime();
    }

    public static String millis2String(long timeStamp, String pattern) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        return simpleDateFormat.format(new Date(timeStamp));
    }

    public static long string2Millis(String time, String pattern) {
        try {
            SimpleDateFormat format = new SimpleDateFormat(pattern);
            return format.parse(time).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return -1;
    }
}
